import { emptyHandle, timestampToTime } from '@vc/utils';
import type { IColumnsOption } from 'vc';
import { INDEX, renderFileJump } from '@/utils/tableColumn';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    {
      width: 111,
      field: 'date',
      title: '发布日期',
      align: 'center',
      formatter: ({ row }) => {
        return emptyHandle(timestampToTime(row.date));
      },
      sortable: true
    },
    {
      width: 590,
      field: 'title',
      align: 'left',
      title: '标题',
      slots: {
        default: ({ row }) => renderFileJump(row, row.title)
      }
    },
    {
      width: 177,
      title: '类型',
      align: 'left',
      slots: {
        default: ({ row }) => {
          return row?.labels?.length ? <span class="label">{row.labels[0]?.name.replace(/#/g, '')}</span> : '-';
        }
      }
    },
    {
      align: 'center',
      field: 'source',
      title: '来源'
    }
  ]);

  return {
    columns
  };
}
